package com.yc.healthy.controller;


import com.yc.healthy.entity.Category;
import com.yc.healthy.entity.Result;
import com.yc.healthy.mapper.CategoryMapper;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyl
 * @since 2023-03-08
 */
@Controller
@RequestMapping("/healthy/category")
public class CategoryController {

    @Resource
    CategoryMapper categoryMapper;

    @PostMapping("querybyctype")
    @ResponseBody
    public Result queryBytype(@RequestParam("type") String type){
        List<Category> categories = categoryMapper.SelectBytype(type);
        System.out.println(categories);
        if (categories.isEmpty()){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",categories);
        }

    }

    @PostMapping("querybyCid")
    @ResponseBody
    public Result queryByid( int id){
        Category category = categoryMapper.QueryById(id);
        if ("".equals(category) || category == null){
            return new Result(0,"查无数据",null);
        }else {
            return new Result(1,"查询成功",category);
        }
    }
}

